<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>MiXiM: Flood Class Reference</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>


</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">MiXiM
   &#160;<span id="projectnumber">2.3</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="classes.html"><span>Class&#160;Index</span></a></li>
      <li><a href="inherits.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('a00094.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="summary">
<a href="#nested-classes">Classes</a> &#124;
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="#pro-types">Protected Types</a> &#124;
<a href="#pro-methods">Protected Member Functions</a> &#124;
<a href="#pro-attribs">Protected Attributes</a>  </div>
  <div class="headertitle">
<div class="title">Flood Class Reference<div class="ingroups"><a class="el" href="a00507.html">netwLayer - network layer modules</a></div></div>  </div>
</div>
<div class="contents">
<!-- doxytag: class="Flood" --><!-- doxytag: inherits="BaseNetwLayer" -->
<p>A simple flooding protocol.  
 <a href="a00094.html#details">More...</a></p>

<p><code>#include &lt;<a class="el" href="a00450_source.html">Flood.h</a>&gt;</code></p>
<div class="dynheader">
Inheritance diagram for Flood:</div>
<div class="dyncontent">
<div class="center"><img src="a00751.png" border="0" usemap="#Flood_inherit__map" alt="Inheritance graph"/></div>
<center><span class="legend">[<a target="top" href="graph_legend.html">legend</a>]</span></center></div>
<div class="dynheader">
Collaboration diagram for Flood:</div>
<div class="dyncontent">
<div class="center"><img src="a00752.png" border="0" usemap="#Flood_coll__map" alt="Collaboration graph"/></div>
<center><span class="legend">[<a target="top" href="graph_legend.html">legend</a>]</span></center></div>

<p><a href="a00753.html">List of all members.</a></p>
<table class="memberdecls">
<tr><td colspan="2"><h2><a name="nested-classes"></a>
Classes</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">class &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00034.html">Bcast</a></td></tr>
<tr><td colspan="2"><h2><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00094.html#ab47e1d524db55d57edc7f86db5d92735">initialize</a> (int)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Initialization of omnetpp.ini parameters.  <a href="#ab47e1d524db55d57edc7f86db5d92735"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="acf27b1fb0d68b08a1ea752f2ff08b0a4"></a><!-- doxytag: member="Flood::finish" ref="acf27b1fb0d68b08a1ea752f2ff08b0a4" args="()" -->
virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00094.html#acf27b1fb0d68b08a1ea752f2ff08b0a4">finish</a> ()</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Called when the simulation has finished. <br/></td></tr>
<tr><td colspan="2"><h2><a name="pro-types"></a>
Protected Types</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="aa86c6dbba4ab62a707dcd62cb83ada23"></a><!-- doxytag: member="Flood::cBroadcastList" ref="aa86c6dbba4ab62a707dcd62cb83ada23" args="" -->
typedef std::list&lt; <a class="el" href="a00034.html">Bcast</a> &gt;&#160;</td><td class="memItemRight" valign="bottom"><b>cBroadcastList</b></td></tr>
<tr><td colspan="2"><h2><a name="pro-methods"></a>
Protected Member Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00094.html#a37fea31a3b2493ee86f1b3efa7dd885a">handleUpperMsg</a> (cMessage *)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Handle messages from upper layer.  <a href="#a37fea31a3b2493ee86f1b3efa7dd885a"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00094.html#ac8c12c3b58ff0f5092b2326f694a509e">handleLowerMsg</a> (cMessage *)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Handle messages from lower layer.  <a href="#ac8c12c3b58ff0f5092b2326f694a509e"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ac684a409e61e05e4058e9846ad021ca9"></a><!-- doxytag: member="Flood::handleSelfMsg" ref="ac684a409e61e05e4058e9846ad021ca9" args="(cMessage *)" -->
virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00094.html#ac684a409e61e05e4058e9846ad021ca9">handleSelfMsg</a> (cMessage *)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">we have no self messages <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00094.html#ad1cd56d510b11f5ff37daba9d762ebb6">notBroadcasted</a> (<a class="el" href="a00028.html#a70ef917f412c70e361b698d6989e677f">netwpkt_ptr_t</a>)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Checks whether a message was already broadcasted.  <a href="#ad1cd56d510b11f5ff37daba9d762ebb6"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual <a class="el" href="a00028.html#a70ef917f412c70e361b698d6989e677f">netwpkt_ptr_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00094.html#a4576a635c66d17c2a4f05cc6ee524791">encapsMsg</a> (cPacket *)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Encapsulate higher layer packet into an NetwPkt.  <a href="#a4576a635c66d17c2a4f05cc6ee524791"></a><br/></td></tr>
<tr><td colspan="2"><h2><a name="pro-attribs"></a>
Protected Attributes</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a5fbbab943e750dc83ed4cb6450b83ea7"></a><!-- doxytag: member="Flood::seqNum" ref="a5fbbab943e750dc83ed4cb6450b83ea7" args="" -->
unsigned long&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00094.html#a5fbbab943e750dc83ed4cb6450b83ea7">seqNum</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Network layer sequence number. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ade22f0280705a8bc6ffbcddeb53a13e2"></a><!-- doxytag: member="Flood::defaultTtl" ref="ade22f0280705a8bc6ffbcddeb53a13e2" args="" -->
int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00094.html#ade22f0280705a8bc6ffbcddeb53a13e2">defaultTtl</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Default time-to-live (ttl) used for this module. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a475a6974782a10907352b83c18b63a21"></a><!-- doxytag: member="Flood::plainFlooding" ref="a475a6974782a10907352b83c18b63a21" args="" -->
bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00094.html#a475a6974782a10907352b83c18b63a21">plainFlooding</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Defines whether to use plain flooding or not. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="aa791a274b5cca9a70f8a484d0b4d9f25"></a><!-- doxytag: member="Flood::bcMsgs" ref="aa791a274b5cca9a70f8a484d0b4d9f25" args="" -->
cBroadcastList&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00094.html#aa791a274b5cca9a70f8a484d0b4d9f25">bcMsgs</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">List of already broadcasted messages. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a8573f479f7cebbcf51efc90d5068b4a3"></a><!-- doxytag: member="Flood::bcMaxEntries" ref="a8573f479f7cebbcf51efc90d5068b4a3" args="" -->
unsigned int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00094.html#a8573f479f7cebbcf51efc90d5068b4a3">bcMaxEntries</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Max number of entries in the list of already broadcasted messages. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a0ebe4588526fe16bede5b8fb75506265"></a><!-- doxytag: member="Flood::bcDelTime" ref="a0ebe4588526fe16bede5b8fb75506265" args="" -->
simtime_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00094.html#a0ebe4588526fe16bede5b8fb75506265">bcDelTime</a></td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Time after which an entry for an already broadcasted msg can be deleted. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="aa261dbd0a1c54f07da4e8fa13a07b821"></a><!-- doxytag: member="Flood::nbDataPacketsReceived" ref="aa261dbd0a1c54f07da4e8fa13a07b821" args="" -->
long&#160;</td><td class="memItemRight" valign="bottom"><b>nbDataPacketsReceived</b></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="afe0eabe3bfd53e1195e3876f8b18b520"></a><!-- doxytag: member="Flood::nbDataPacketsSent" ref="afe0eabe3bfd53e1195e3876f8b18b520" args="" -->
long&#160;</td><td class="memItemRight" valign="bottom"><b>nbDataPacketsSent</b></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="aceac6b52cb227c09f3f3d8d2b7e12f55"></a><!-- doxytag: member="Flood::nbDataPacketsForwarded" ref="aceac6b52cb227c09f3f3d8d2b7e12f55" args="" -->
long&#160;</td><td class="memItemRight" valign="bottom"><b>nbDataPacketsForwarded</b></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ae102cca4d79c56b99bc641688465ffc4"></a><!-- doxytag: member="Flood::nbHops" ref="ae102cca4d79c56b99bc641688465ffc4" args="" -->
long&#160;</td><td class="memItemRight" valign="bottom"><b>nbHops</b></td></tr>
</table>
<hr/><a name="details" id="details"></a><h2>Detailed Description</h2>
<div class="textblock"><p>A simple flooding protocol. </p>
<p>This implementation uses plain flooding, i.e. it "remembers" (stores) already broadcasted messages in a list and does not rebroadcast them again, if it gets another copy of that message.</p>
<p>The maximum number of entires for that list can be defined in the .ini file (<a class="el" href="a00094.html#a8573f479f7cebbcf51efc90d5068b4a3">bcMaxEntries</a>) as well as the time after which an entry is deleted (<a class="el" href="a00094.html#a0ebe4588526fe16bede5b8fb75506265">bcDelTime</a>).</p>
<p>If you prefere a memory-less version you can comment out the </p>
<div class="fragment"><pre class="fragment">#define PLAINFLOODING </pre></div><dl class="author"><dt><b>Author:</b></dt><dd>Daniel Willkomm</dd></dl>
<p>ported to Mixim 2.0 by Theodoros Kapourniotis </p>
</div><hr/><h2>Member Function Documentation</h2>
<a class="anchor" id="a4576a635c66d17c2a4f05cc6ee524791"></a><!-- doxytag: member="Flood::encapsMsg" ref="a4576a635c66d17c2a4f05cc6ee524791" args="(cPacket *)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="a00028.html#a70ef917f412c70e361b698d6989e677f">Flood::netwpkt_ptr_t</a> Flood::encapsMsg </td>
          <td>(</td>
          <td class="paramtype">cPacket *&#160;</td>
          <td class="paramname"><em>appPkt</em></td><td>)</td>
          <td><code> [protected, virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Encapsulate higher layer packet into an NetwPkt. </p>
<p>Encapsulates the received ApplPkt into a NetwPkt and set all needed header fields. </p>

<p>Reimplemented from <a class="el" href="a00028.html#aad9d232f77fa033ffa2f1e7abe8e4af6">BaseNetwLayer</a>.</p>

<p>References <a class="el" href="a00155.html#a75c4c6c2073fcd17b73583b7243e8d21">NetwControlInfo::getAddressFromControlInfo()</a>, <a class="el" href="a00028.html#a9b802bd94a739e6202690d743ecc83a2">BaseNetwLayer::headerLength</a>, <a class="el" href="a00117.html#a9f975ad0433f1fb8a01164f266a41f62">LAddress::L2BROADCAST</a>, <a class="el" href="a00117.html#a11d63e8d897e072ed94da77028d38f60">LAddress::L3BROADCAST</a>, <a class="el" href="a00028.html#a7df0d33fcf757b2e63af619f28bf3312">BaseNetwLayer::myNetwAddr</a>, and <a class="el" href="a00028.html#a627a9f853785bc061b1423ac6ad9ad21">BaseNetwLayer::setDownControlInfo()</a>.</p>

<p>Referenced by <a class="el" href="a00094.html#a37fea31a3b2493ee86f1b3efa7dd885a">handleUpperMsg()</a>.</p>
<div class="fragment"><pre class="fragment">                                                   {
    <a class="code" href="a00117.html#aea56b60dcb5ae8c2bde465271daf7210" title="Type definition for a L2 (MAC) address.">LAddress::L2Type</a> macAddr;
    <a class="code" href="a00117.html#ad85cd9e8d9e7e9cd5d02dd740c4a12a4" title="Type definition for a L3 (Network) address.">LAddress::L3Type</a> netwAddr;

    EV&lt;&lt;<span class="stringliteral">&quot;in encaps...\n&quot;</span>;

    <a class="code" href="a00028.html#a70ef917f412c70e361b698d6989e677f" title="network packet pointer type.">netwpkt_ptr_t</a> pkt = <span class="keyword">new</span> NetwPkt(appPkt-&gt;getName(), appPkt-&gt;getKind());
    pkt-&gt;setBitLength(<a class="code" href="a00028.html#a9b802bd94a739e6202690d743ecc83a2" title="Length of the NetwPkt header Read from omnetpp.ini.">headerLength</a>);

    cObject* cInfo = appPkt-&gt;removeControlInfo();

    <span class="keywordflow">if</span>(cInfo == NULL){
  EV &lt;&lt; <span class="stringliteral">&quot;warning: Application layer did not specifiy a destination L3 address\n&quot;</span>
     &lt;&lt; <span class="stringliteral">&quot;\tusing broadcast address instead\n&quot;</span>;
  netwAddr = <a class="code" href="a00117.html#a11d63e8d897e072ed94da77028d38f60" title="Broadcast address for L3 addresses.">LAddress::L3BROADCAST</a>;
    } <span class="keywordflow">else</span> {
  EV &lt;&lt;<span class="stringliteral">&quot;CInfo removed, netw addr=&quot;</span>&lt;&lt; <a class="code" href="a00155.html#a75c4c6c2073fcd17b73583b7243e8d21" title="extracts the address from &quot;control info&quot;.">NetwControlInfo::getAddressFromControlInfo</a>( cInfo ) &lt;&lt;endl;
        netwAddr = <a class="code" href="a00155.html#a75c4c6c2073fcd17b73583b7243e8d21" title="extracts the address from &quot;control info&quot;.">NetwControlInfo::getAddressFromControlInfo</a>( cInfo );
  <span class="keyword">delete</span> cInfo;
    }

    pkt-&gt;setSrcAddr(<a class="code" href="a00028.html#a7df0d33fcf757b2e63af619f28bf3312" title="cached variable of my networ address">myNetwAddr</a>);
    pkt-&gt;setDestAddr(netwAddr);
    EV &lt;&lt; <span class="stringliteral">&quot; netw &quot;</span>&lt;&lt; <a class="code" href="a00028.html#a7df0d33fcf757b2e63af619f28bf3312" title="cached variable of my networ address">myNetwAddr</a> &lt;&lt; <span class="stringliteral">&quot; sending packet&quot;</span> &lt;&lt;endl;

    EV &lt;&lt; <span class="stringliteral">&quot;sendDown: nHop=L3BROADCAST -&gt; message has to be broadcasted&quot;</span>
       &lt;&lt; <span class="stringliteral">&quot; -&gt; set destMac=L2BROADCAST&quot;</span> &lt;&lt; endl;
    macAddr = <a class="code" href="a00117.html#a9f975ad0433f1fb8a01164f266a41f62" title="Broadcast address for L2 addresses.">LAddress::L2BROADCAST</a>;

    <a class="code" href="a00028.html#a627a9f853785bc061b1423ac6ad9ad21" title="Attaches a &quot;control info&quot; (NetwToMac) structure (object) to the message pMsg.">setDownControlInfo</a>(pkt, macAddr);

    <span class="comment">//encapsulate the application packet</span>
    pkt-&gt;encapsulate(appPkt);
    EV &lt;&lt;<span class="stringliteral">&quot; pkt encapsulated\n&quot;</span>;
    <span class="keywordflow">return</span> pkt;
}
</pre></div>
</div>
</div>
<a class="anchor" id="ac8c12c3b58ff0f5092b2326f694a509e"></a><!-- doxytag: member="Flood::handleLowerMsg" ref="ac8c12c3b58ff0f5092b2326f694a509e" args="(cMessage *)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Flood::handleLowerMsg </td>
          <td>(</td>
          <td class="paramtype">cMessage *&#160;</td>
          <td class="paramname"><em>m</em></td><td>)</td>
          <td><code> [protected, virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Handle messages from lower layer. </p>
<p>Messages from the mac layer will be forwarded to the application only if the are broadcast or destined for this node.</p>
<p>If the arrived message is a broadcast message it is also reflooded only if the tll field is bigger than one. Before the message is handed back to the mac layer the ttl field is reduced by one to account for this hop.</p>
<p>In the case of plain flooding the message will only be processed if there is no corresponding entry in the bcMsgs list (<a class="el" href="a00094.html#ad1cd56d510b11f5ff37daba9d762ebb6">notBroadcasted</a>). Otherwise the message will be deleted. </p>

<p>Reimplemented from <a class="el" href="a00028.html#a58afc64e0a96fe4d80d6b9f53cfd53c6">BaseNetwLayer</a>.</p>

<p>References <a class="el" href="a00028.html#a5e35aa24556a7cab9b6658889e98cb74">BaseNetwLayer::decapsMsg()</a>, <a class="el" href="a00094.html#ade22f0280705a8bc6ffbcddeb53a13e2">defaultTtl</a>, <a class="el" href="a00117.html#a97a5c1c1f73f4255cabc4e292c4ad503">LAddress::isL3Broadcast()</a>, <a class="el" href="a00117.html#a9f975ad0433f1fb8a01164f266a41f62">LAddress::L2BROADCAST</a>, <a class="el" href="a00028.html#a7df0d33fcf757b2e63af619f28bf3312">BaseNetwLayer::myNetwAddr</a>, <a class="el" href="a00094.html#ad1cd56d510b11f5ff37daba9d762ebb6">notBroadcasted()</a>, <a class="el" href="a00025.html#a1873d6e3fc6d92cf8482b39f1c5ac6c8">BaseLayer::sendDown()</a>, <a class="el" href="a00025.html#adbf061566606041db811b519f0400ed5">BaseLayer::sendUp()</a>, and <a class="el" href="a00028.html#a627a9f853785bc061b1423ac6ad9ad21">BaseNetwLayer::setDownControlInfo()</a>.</p>
<div class="fragment"><pre class="fragment">                                      {
    <a class="code" href="a00028.html#a70ef917f412c70e361b698d6989e677f" title="network packet pointer type.">netwpkt_ptr_t</a> msg = <span class="keyword">static_cast&lt;</span><a class="code" href="a00028.html#a70ef917f412c70e361b698d6989e677f" title="network packet pointer type.">netwpkt_ptr_t</a><span class="keyword">&gt;</span> (m);

  <span class="comment">//msg not broadcastes yet</span>
  <span class="keywordflow">if</span> (<a class="code" href="a00094.html#ad1cd56d510b11f5ff37daba9d762ebb6" title="Checks whether a message was already broadcasted.">notBroadcasted</a>(msg)) {
    <span class="comment">//msg is for me</span>
    <span class="keywordflow">if</span> (msg-&gt;getDestAddr() == <a class="code" href="a00028.html#a7df0d33fcf757b2e63af619f28bf3312" title="cached variable of my networ address">myNetwAddr</a>) {
      EV&lt;&lt;<span class="stringliteral">&quot; data msg for me! send to Upper&quot;</span>&lt;&lt;endl;
      nbHops = nbHops + (<a class="code" href="a00094.html#ade22f0280705a8bc6ffbcddeb53a13e2" title="Default time-to-live (ttl) used for this module.">defaultTtl</a> + 1 - msg-&gt;getTtl());
      <a class="code" href="a00025.html#adbf061566606041db811b519f0400ed5" title="Sends a message to the upper layer.">sendUp</a>( <a class="code" href="a00028.html#a5e35aa24556a7cab9b6658889e98cb74" title="decapsulate higher layer message from NetwPkt">decapsMsg</a>(msg) );
      nbDataPacketsReceived++;
    }
    <span class="comment">//broadcast message</span>
    <span class="keywordflow">else</span> <span class="keywordflow">if</span>( <a class="code" href="a00117.html#a97a5c1c1f73f4255cabc4e292c4ad503" title="Test if a L3 address (pSrcAddr) is a broadcast address.">LAddress::isL3Broadcast</a>(msg-&gt;getDestAddr()) ) {
      <span class="comment">//check ttl and rebroadcast</span>
      <span class="keywordflow">if</span>( msg-&gt;getTtl() &gt; 1 ) {
          <a class="code" href="a00028.html#a70ef917f412c70e361b698d6989e677f" title="network packet pointer type.">netwpkt_ptr_t</a> dMsg;
        EV &lt;&lt;<span class="stringliteral">&quot; data msg BROADCAST! ttl = &quot;</span>&lt;&lt;msg-&gt;getTtl()
        &lt;&lt;<span class="stringliteral">&quot; &gt; 1 -&gt; rebroadcast msg &amp; send to upper\n&quot;</span>;
        msg-&gt;setTtl( msg-&gt;getTtl()-1 );
        dMsg = <span class="keyword">static_cast&lt;</span><a class="code" href="a00028.html#a70ef917f412c70e361b698d6989e677f" title="network packet pointer type.">netwpkt_ptr_t</a><span class="keyword">&gt;</span>(msg-&gt;dup());
        <a class="code" href="a00028.html#a627a9f853785bc061b1423ac6ad9ad21" title="Attaches a &quot;control info&quot; (NetwToMac) structure (object) to the message pMsg.">setDownControlInfo</a>(dMsg, <a class="code" href="a00117.html#a9f975ad0433f1fb8a01164f266a41f62" title="Broadcast address for L2 addresses.">LAddress::L2BROADCAST</a>);
        <a class="code" href="a00025.html#a1873d6e3fc6d92cf8482b39f1c5ac6c8" title="Sends a message to the lower layer.">sendDown</a>(dMsg);
        nbDataPacketsForwarded++;
      }
      <span class="keywordflow">else</span>
      EV &lt;&lt;<span class="stringliteral">&quot; max hops reached (ttl = &quot;</span>&lt;&lt;msg-&gt;getTtl()&lt;&lt;<span class="stringliteral">&quot;) -&gt; only send to upper\n&quot;</span>;

      <span class="comment">// message has to be forwarded to upper layer</span>
      nbHops = nbHops + (<a class="code" href="a00094.html#ade22f0280705a8bc6ffbcddeb53a13e2" title="Default time-to-live (ttl) used for this module.">defaultTtl</a> + 1 - msg-&gt;getTtl());
      <a class="code" href="a00025.html#adbf061566606041db811b519f0400ed5" title="Sends a message to the upper layer.">sendUp</a>( <a class="code" href="a00028.html#a5e35aa24556a7cab9b6658889e98cb74" title="decapsulate higher layer message from NetwPkt">decapsMsg</a>(msg) );
      nbDataPacketsReceived++;
    }
    <span class="comment">//not for me -&gt; rebroadcast</span>
    <span class="keywordflow">else</span> {
      <span class="comment">//check ttl and rebroadcast</span>
      <span class="keywordflow">if</span>( msg-&gt;getTtl() &gt; 1 ) {
        EV &lt;&lt;<span class="stringliteral">&quot; data msg not for me! ttl = &quot;</span>&lt;&lt;msg-&gt;getTtl()
        &lt;&lt;<span class="stringliteral">&quot; &gt; 1 -&gt; forward\n&quot;</span>;
        msg-&gt;setTtl( msg-&gt;getTtl()-1 );
        <span class="comment">// needs to set the next hop address again to broadcast</span>
        cObject *<span class="keyword">const</span> pCtrlInfo = msg-&gt;removeControlInfo();
        <span class="keywordflow">if</span> (pCtrlInfo != NULL)
          <span class="keyword">delete</span> pCtrlInfo;
        <a class="code" href="a00028.html#a627a9f853785bc061b1423ac6ad9ad21" title="Attaches a &quot;control info&quot; (NetwToMac) structure (object) to the message pMsg.">setDownControlInfo</a>(msg, <a class="code" href="a00117.html#a9f975ad0433f1fb8a01164f266a41f62" title="Broadcast address for L2 addresses.">LAddress::L2BROADCAST</a>);
        <a class="code" href="a00025.html#a1873d6e3fc6d92cf8482b39f1c5ac6c8" title="Sends a message to the lower layer.">sendDown</a>( msg );
        nbDataPacketsForwarded++;
      }
      <span class="keywordflow">else</span> {
        <span class="comment">//max hops reached -&gt; delete</span>
        EV &lt;&lt;<span class="stringliteral">&quot; max hops reached (ttl = &quot;</span>&lt;&lt;msg-&gt;getTtl()&lt;&lt;<span class="stringliteral">&quot;) -&gt; delete msg\n&quot;</span>;
        <span class="keyword">delete</span> msg;
      }
    }
  }
  <span class="keywordflow">else</span> {
    EV &lt;&lt;<span class="stringliteral">&quot; data msg already BROADCASTed! delete msg\n&quot;</span>;
    <span class="keyword">delete</span> msg;
  }
}
</pre></div>
</div>
</div>
<a class="anchor" id="a37fea31a3b2493ee86f1b3efa7dd885a"></a><!-- doxytag: member="Flood::handleUpperMsg" ref="a37fea31a3b2493ee86f1b3efa7dd885a" args="(cMessage *)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Flood::handleUpperMsg </td>
          <td>(</td>
          <td class="paramtype">cMessage *&#160;</td>
          <td class="paramname"><em>m</em></td><td>)</td>
          <td><code> [protected, virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Handle messages from upper layer. </p>
<p>All messages have to get a sequence number and the ttl filed has to be specified. Afterwards the messages can be handed to the mac layer. The mac address is set to -1 (broadcast address) because the message is flooded (i.e. has to be send to all neighbors)</p>
<p>In the case of plain flooding the message sequence number and source address has also be stored in the bcMsgs list, so that this message will not be rebroadcasted, if a copy will be flooded back from the neigbouring nodes.</p>
<p>If the maximum number of entries is reached the first (oldest) entry is deleted. </p>

<p>Reimplemented from <a class="el" href="a00028.html#a0b473fbb2517ac7b0c633afdb002c269">BaseNetwLayer</a>.</p>

<p>References <a class="el" href="a00094.html#a0ebe4588526fe16bede5b8fb75506265">bcDelTime</a>, <a class="el" href="a00094.html#a8573f479f7cebbcf51efc90d5068b4a3">bcMaxEntries</a>, <a class="el" href="a00094.html#aa791a274b5cca9a70f8a484d0b4d9f25">bcMsgs</a>, <a class="el" href="a00094.html#ade22f0280705a8bc6ffbcddeb53a13e2">defaultTtl</a>, <a class="el" href="a00094.html#a4576a635c66d17c2a4f05cc6ee524791">encapsMsg()</a>, <a class="el" href="a00094.html#a475a6974782a10907352b83c18b63a21">plainFlooding</a>, <a class="el" href="a00025.html#a1873d6e3fc6d92cf8482b39f1c5ac6c8">BaseLayer::sendDown()</a>, and <a class="el" href="a00094.html#a5fbbab943e750dc83ed4cb6450b83ea7">seqNum</a>.</p>
<div class="fragment"><pre class="fragment">                                      {

  assert(dynamic_cast&lt;cPacket*&gt; (m));
  <a class="code" href="a00028.html#a70ef917f412c70e361b698d6989e677f" title="network packet pointer type.">netwpkt_ptr_t</a> msg = <a class="code" href="a00094.html#a4576a635c66d17c2a4f05cc6ee524791" title="Encapsulate higher layer packet into an NetwPkt.">encapsMsg</a>(static_cast&lt;cPacket*&gt; (m));

  msg-&gt;setSeqNum(<a class="code" href="a00094.html#a5fbbab943e750dc83ed4cb6450b83ea7" title="Network layer sequence number.">seqNum</a>);
  <a class="code" href="a00094.html#a5fbbab943e750dc83ed4cb6450b83ea7" title="Network layer sequence number.">seqNum</a>++;
  msg-&gt;setTtl(<a class="code" href="a00094.html#ade22f0280705a8bc6ffbcddeb53a13e2" title="Default time-to-live (ttl) used for this module.">defaultTtl</a>);

  <span class="keywordflow">if</span> (<a class="code" href="a00094.html#a475a6974782a10907352b83c18b63a21" title="Defines whether to use plain flooding or not.">plainFlooding</a>) {
    <span class="keywordflow">if</span> (<a class="code" href="a00094.html#aa791a274b5cca9a70f8a484d0b4d9f25" title="List of already broadcasted messages.">bcMsgs</a>.size() &gt;= <a class="code" href="a00094.html#a8573f479f7cebbcf51efc90d5068b4a3" title="Max number of entries in the list of already broadcasted messages.">bcMaxEntries</a>) {
      cBroadcastList::iterator it;

      <span class="comment">//serach the broadcast list of outdated entries and delete them</span>
      <span class="keywordflow">for</span> (it = <a class="code" href="a00094.html#aa791a274b5cca9a70f8a484d0b4d9f25" title="List of already broadcasted messages.">bcMsgs</a>.begin(); it != <a class="code" href="a00094.html#aa791a274b5cca9a70f8a484d0b4d9f25" title="List of already broadcasted messages.">bcMsgs</a>.end(); ++it) {
        <span class="keywordflow">if</span> (it-&gt;delTime &lt; simTime()) {
          <a class="code" href="a00094.html#aa791a274b5cca9a70f8a484d0b4d9f25" title="List of already broadcasted messages.">bcMsgs</a>.erase(it);
          it--;
          <span class="keywordflow">break</span>;
        }
      }
      <span class="comment">//delete oldest entry if max size is reached</span>
      <span class="keywordflow">if</span> (<a class="code" href="a00094.html#aa791a274b5cca9a70f8a484d0b4d9f25" title="List of already broadcasted messages.">bcMsgs</a>.size() &gt;= <a class="code" href="a00094.html#a8573f479f7cebbcf51efc90d5068b4a3" title="Max number of entries in the list of already broadcasted messages.">bcMaxEntries</a>) {
        EV&lt;&lt;<span class="stringliteral">&quot;bcMsgs is full, delete oldest entry&quot;</span>&lt;&lt;endl;
        <a class="code" href="a00094.html#aa791a274b5cca9a70f8a484d0b4d9f25" title="List of already broadcasted messages.">bcMsgs</a>.pop_front();
      }
    }
    <a class="code" href="a00094.html#aa791a274b5cca9a70f8a484d0b4d9f25" title="List of already broadcasted messages.">bcMsgs</a>.push_back(Bcast(msg-&gt;getSeqNum(), msg-&gt;getSrcAddr(), simTime() +<a class="code" href="a00094.html#a0ebe4588526fe16bede5b8fb75506265" title="Time after which an entry for an already broadcasted msg can be deleted.">bcDelTime</a>));
    }
        <span class="comment">//there is no routing so all messages are broadacst for the mac layer</span>

        <a class="code" href="a00025.html#a1873d6e3fc6d92cf8482b39f1c5ac6c8" title="Sends a message to the lower layer.">sendDown</a>(msg);
        nbDataPacketsSent++;
      }
</pre></div>
</div>
</div>
<a class="anchor" id="ab47e1d524db55d57edc7f86db5d92735"></a><!-- doxytag: member="Flood::initialize" ref="ab47e1d524db55d57edc7f86db5d92735" args="(int)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Flood::initialize </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>stage</em></td><td>)</td>
          <td><code> [virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Initialization of omnetpp.ini parameters. </p>
<p>Reads all parameters from the ini file. If a parameter is not specified in the ini file a default value will be set. </p>

<p>Reimplemented from <a class="el" href="a00028.html#a1e521b5549bfe29ae94d95265c0fe8d2">BaseNetwLayer</a>.</p>

<p>References <a class="el" href="a00094.html#a0ebe4588526fe16bede5b8fb75506265">bcDelTime</a>, <a class="el" href="a00094.html#a8573f479f7cebbcf51efc90d5068b4a3">bcMaxEntries</a>, <a class="el" href="a00094.html#ade22f0280705a8bc6ffbcddeb53a13e2">defaultTtl</a>, <a class="el" href="a00094.html#a475a6974782a10907352b83c18b63a21">plainFlooding</a>, and <a class="el" href="a00094.html#a5fbbab943e750dc83ed4cb6450b83ea7">seqNum</a>.</p>
<div class="fragment"><pre class="fragment">                                {
  <a class="code" href="a00094.html#ab47e1d524db55d57edc7f86db5d92735" title="Initialization of omnetpp.ini parameters.">BaseNetwLayer::initialize</a>(stage);

  <span class="keywordflow">if</span> (stage == 0) {
    <span class="comment">//initialize seqence number to 0</span>
    <a class="code" href="a00094.html#a5fbbab943e750dc83ed4cb6450b83ea7" title="Network layer sequence number.">seqNum</a> = 0;
    nbDataPacketsReceived = 0;
    nbDataPacketsSent = 0;
    nbDataPacketsForwarded = 0;
    nbHops = 0;
    hasPar(<span class="stringliteral">&quot;defaultTtl&quot;</span>) ? <a class="code" href="a00094.html#ade22f0280705a8bc6ffbcddeb53a13e2" title="Default time-to-live (ttl) used for this module.">defaultTtl</a> = par(<span class="stringliteral">&quot;defaultTtl&quot;</span>) : <a class="code" href="a00094.html#ade22f0280705a8bc6ffbcddeb53a13e2" title="Default time-to-live (ttl) used for this module.">defaultTtl</a> = 5;
    hasPar(<span class="stringliteral">&quot;plainFlooding&quot;</span>) ? <a class="code" href="a00094.html#a475a6974782a10907352b83c18b63a21" title="Defines whether to use plain flooding or not.">plainFlooding</a> = par(<span class="stringliteral">&quot;plainFlooding&quot;</span>)
        : <a class="code" href="a00094.html#a475a6974782a10907352b83c18b63a21" title="Defines whether to use plain flooding or not.">plainFlooding</a> = true;

    EV&lt;&lt; <span class="stringliteral">&quot;defaultTtl = &quot;</span> &lt;&lt; <a class="code" href="a00094.html#ade22f0280705a8bc6ffbcddeb53a13e2" title="Default time-to-live (ttl) used for this module.">defaultTtl</a>
    &lt;&lt; <span class="stringliteral">&quot; plainFlooding = &quot;</span> &lt;&lt; <a class="code" href="a00094.html#a475a6974782a10907352b83c18b63a21" title="Defines whether to use plain flooding or not.">plainFlooding</a> &lt;&lt; endl;

    <span class="keywordflow">if</span>(<a class="code" href="a00094.html#a475a6974782a10907352b83c18b63a21" title="Defines whether to use plain flooding or not.">plainFlooding</a>) {
      <span class="comment">//these parameters are only needed for plain flooding</span>
      hasPar(<span class="stringliteral">&quot;bcMaxEntries&quot;</span>) ? <a class="code" href="a00094.html#a8573f479f7cebbcf51efc90d5068b4a3" title="Max number of entries in the list of already broadcasted messages.">bcMaxEntries</a> = par(<span class="stringliteral">&quot;bcMaxEntries&quot;</span>) : <a class="code" href="a00094.html#a8573f479f7cebbcf51efc90d5068b4a3" title="Max number of entries in the list of already broadcasted messages.">bcMaxEntries</a> = 30;

      hasPar(<span class="stringliteral">&quot;bcDelTime&quot;</span>) ? <a class="code" href="a00094.html#a0ebe4588526fe16bede5b8fb75506265" title="Time after which an entry for an already broadcasted msg can be deleted.">bcDelTime</a> = par(<span class="stringliteral">&quot;bcDelTime&quot;</span>).doubleValue() : <a class="code" href="a00094.html#a0ebe4588526fe16bede5b8fb75506265" title="Time after which an entry for an already broadcasted msg can be deleted.">bcDelTime</a> = 3.0;
      EV &lt;&lt;<span class="stringliteral">&quot;bcMaxEntries = &quot;</span>&lt;&lt;<a class="code" href="a00094.html#a8573f479f7cebbcf51efc90d5068b4a3" title="Max number of entries in the list of already broadcasted messages.">bcMaxEntries</a>
      &lt;&lt;<span class="stringliteral">&quot; bcDelTime = &quot;</span>&lt;&lt;<a class="code" href="a00094.html#a0ebe4588526fe16bede5b8fb75506265" title="Time after which an entry for an already broadcasted msg can be deleted.">bcDelTime</a>&lt;&lt;endl;
    }
  }
}
</pre></div>
</div>
</div>
<a class="anchor" id="ad1cd56d510b11f5ff37daba9d762ebb6"></a><!-- doxytag: member="Flood::notBroadcasted" ref="ad1cd56d510b11f5ff37daba9d762ebb6" args="(netwpkt_ptr_t)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool Flood::notBroadcasted </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="a00028.html#a70ef917f412c70e361b698d6989e677f">netwpkt_ptr_t</a>&#160;</td>
          <td class="paramname"><em>msg</em></td><td>)</td>
          <td><code> [protected]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Checks whether a message was already broadcasted. </p>
<p>The bcMsgs list is searched for the arrived message. If the message is in the list, it was already broadcasted and the function returns false.</p>
<p>Concurrently all outdated (older than bcDelTime) are deleted. If the list is full and a new message has to be entered, the oldest entry is deleted. </p>

<p>References <a class="el" href="a00094.html#a0ebe4588526fe16bede5b8fb75506265">bcDelTime</a>, <a class="el" href="a00094.html#a8573f479f7cebbcf51efc90d5068b4a3">bcMaxEntries</a>, <a class="el" href="a00094.html#aa791a274b5cca9a70f8a484d0b4d9f25">bcMsgs</a>, and <a class="el" href="a00094.html#a475a6974782a10907352b83c18b63a21">plainFlooding</a>.</p>

<p>Referenced by <a class="el" href="a00094.html#ac8c12c3b58ff0f5092b2326f694a509e">handleLowerMsg()</a>.</p>
<div class="fragment"><pre class="fragment">                                            {
  <span class="keywordflow">if</span> (!<a class="code" href="a00094.html#a475a6974782a10907352b83c18b63a21" title="Defines whether to use plain flooding or not.">plainFlooding</a>)
    <span class="keywordflow">return</span> <span class="keyword">true</span>;

  cBroadcastList::iterator it;

  <span class="comment">//serach the broadcast list of outdated entries and delete them</span>
  <span class="keywordflow">for</span> (it = <a class="code" href="a00094.html#aa791a274b5cca9a70f8a484d0b4d9f25" title="List of already broadcasted messages.">bcMsgs</a>.begin(); it != <a class="code" href="a00094.html#aa791a274b5cca9a70f8a484d0b4d9f25" title="List of already broadcasted messages.">bcMsgs</a>.end(); it++) {
    <span class="keywordflow">if</span> (it-&gt;delTime &lt; simTime()) {
      <a class="code" href="a00094.html#aa791a274b5cca9a70f8a484d0b4d9f25" title="List of already broadcasted messages.">bcMsgs</a>.erase(it);
      it--;
    }
    <span class="comment">//message was already broadcasted</span>
    <span class="keywordflow">if</span> ((it-&gt;srcAddr == msg-&gt;getSrcAddr()) &amp;&amp; (it-&gt;seqNum
        == msg-&gt;getSeqNum())) {
      <span class="comment">// update entry</span>
      it-&gt;delTime = simTime() + <a class="code" href="a00094.html#a0ebe4588526fe16bede5b8fb75506265" title="Time after which an entry for an already broadcasted msg can be deleted.">bcDelTime</a>;
      <span class="keywordflow">return</span> <span class="keyword">false</span>;
    }
  }

  <span class="comment">//delete oldest entry if max size is reached</span>
  <span class="keywordflow">if</span> (<a class="code" href="a00094.html#aa791a274b5cca9a70f8a484d0b4d9f25" title="List of already broadcasted messages.">bcMsgs</a>.size() &gt;= <a class="code" href="a00094.html#a8573f479f7cebbcf51efc90d5068b4a3" title="Max number of entries in the list of already broadcasted messages.">bcMaxEntries</a>) {
    EV&lt;&lt;<span class="stringliteral">&quot;bcMsgs is full, delete oldest entry\n&quot;</span>;
    <a class="code" href="a00094.html#aa791a274b5cca9a70f8a484d0b4d9f25" title="List of already broadcasted messages.">bcMsgs</a>.pop_front();
  }

  <a class="code" href="a00094.html#aa791a274b5cca9a70f8a484d0b4d9f25" title="List of already broadcasted messages.">bcMsgs</a>.push_back(Bcast(msg-&gt;getSeqNum(), msg-&gt;getSrcAddr(), simTime() +<a class="code" href="a00094.html#a0ebe4588526fe16bede5b8fb75506265" title="Time after which an entry for an already broadcasted msg can be deleted.">bcDelTime</a>));
    <span class="keywordflow">return</span> <span class="keyword">true</span>;
}
</pre></div>
</div>
</div>
<hr/>The documentation for this class was generated from the following files:<ul>
<li>D:/Projects/MiXiM/extsrc/mixim/src/modules/netw/<a class="el" href="a00450_source.html">Flood.h</a></li>
<li>D:/Projects/MiXiM/extsrc/mixim/src/modules/netw/Flood.cc</li>
</ul>
</div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="a00094.html">Flood</a>      </li>

    <li class="footer">Generated on Tue Mar 5 2013 21:26:32 for MiXiM by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>
